package com.huashi.dealer.core.util;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

/**
 * @ClassName TimeUtil
 * @Description 时间转换处理类
 * @Author 谭陈强
 * @Date 2025/8/9 08:16
 */
public class TimeUtil {
    public static LocalDateTime changeToLocalDateTime(Long time) {
        if(time == null|| time == 0 || time == 0L) {
            return null;
        }
        return LocalDateTime.ofEpochSecond(time, 0, ZoneOffset.ofHours(8));
    }

    public static long localDateTimeToTimestamp(LocalDateTime localDateTime) {
        if (localDateTime == null) {
            return 0L;
        }
        return localDateTime.toEpochSecond(ZoneOffset.ofHours(8));
    }

    public static long localDateToTimestamp(LocalDate localDate) {
        if (localDate == null) {
            return 0L;
        }
        return localDate.atStartOfDay(ZoneOffset.ofHours(8)).toEpochSecond();
    }

    public static long localDateToTimestampStartOfDay(LocalDate localDate) {
        if (localDate == null) {
            return 0L;
        }
        return localDate.atStartOfDay(ZoneOffset.ofHours(8)).toEpochSecond();
    }

    public static long localDateToTimestampEndOfDay(LocalDate localDate) {
        if (localDate == null) {
            return 0L;
        }
        return localDate.atTime(23, 59, 59).toEpochSecond(ZoneOffset.ofHours(8));
    }
}